<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item :label=" $t('radio.fileName') ">
              <j-input :placeholder="$t('base.inputVagueQuery')" v-model="queryParam.fileName"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search"> {{$t('base.query')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('base.reset')}}</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{$t('radio.uploadResources')}}</a-button>
      <a-button  @click="batchDel" type="primary" icon="delete">{{$t('base.del')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{$t('base.selected')}} <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> {{$t('base.item')}}
        <a style="margin-left: 24px" @click="onClearSelected">{{$t('base.clear')}}</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a-popconfirm :title=" $t('radio.doYouWantToDeleteIt') " @confirm="() => handleDelete(record.id)">
                  <a>{{$t('base.del')}} </a>
                </a-popconfirm>
          <a-divider type="vertical"/>
           <a href="javascript:;" @click="uploadResourceFile(record.filePath)">下载</a>
        </span>

      </a-table>
    </div>
    <glrResource-modal ref="modalForm" @ok="modalFormOk"></glrResource-modal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GlrResourceModal from './modules/GlrResourceModal'
  import { validateDuplicateValue,filterObj } from '@/utils/util'
  import JInput from '@/components/jeecg/JInput'
  export default {
    name: "GlrResourceList",
    mixins:[JeecgListMixin],
    components: {
      GlrResourceModal,
      JInput
    },
    data () {
      return {
        description: '资源表管理页面',
        disableMixinCreated:true,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
             title:this.$t('radio.fileName') ,
            align:"center",
            dataIndex: 'fileName'
          },
          {
              title: this.$t('radio.fileType') ,
            align:"center",
            dataIndex: 'fileType'
          },
          {
              title: this.$t('radio.fileSizeMb') ,
            align:"center",
            dataIndex: 'fileSize',
            customRender:function (text) {
              return (text/1024/1024).toFixed(2)+'(MB)'
            }
          },
          {
            title:'图片',
            align:"center",
            scopedSlots: {customRender: "avatarslot"}
          },
          {
              title: this.$t('radio.uploadTime')  ,
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
              title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrResource/list",
          delete: "/glr/glrResource/delete",
          deleteBatch: "/glr/glrResource/deleteBatch",
          exportXlsUrl: "/glr/glrResource/exportXls",
          importExcelUrl: "glr/glrResource/importExcel",
        },
        dictOptions:{
        },
      }
    },
    created(){
      this.queryParam.equipmentType = 2;
      this.loadData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      getAvatarView: function (record) {
        if(record.fileType=='.mp4'){
         return  require('@/assets/logo.png')
        }else{
          return window._CONFIG['domianURL'] +"/"+record.filePath;
        }
      },
      /* 文件下载 */
      uploadResourceFile(text){
        if(!text){
          this.$message.warning("未知的文件")
          return;
        }
        if(text.indexOf(",")>0){
          text = text.substring(0,text.indexOf(","))
        }
        window.open(window._CONFIG['domianURL'] + "/glr/glrResource/download/"+text);
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>